<?php

/* 规格 spec */
class SpecModel extends BaseModel
{
	var $table  = 'spec';
	var $prikey = 'spec_id';
	var $_name  = 'spec';
	/* 添加编辑时自动验证 */
	var $_autov = array(
	'spec_name' => array(
	'required'  => true,    //必填
	'min'       => 1,       //最短1个字符
	'max'       => 100,     //最长100个字符
	'filter'    => 'trim',
	),
	'sort_order'  => array(
	'filter'    => 'intval',
	)
	);


	function get_list($cid)
	{
		$sql = "SELECT a.*,c.cate_name FROM {$this->table} a left join " . DB_PREFIX ."gcategory c on a.cate_id = c.cate_id  where a.cate_id = $cid ORDER BY a.sort_order DESC";
		return $this->db->getAll($sql);
	}
	/**
     *    删除商品屬性
     *
     *    @author    Hyber
     *    @param     string $conditions
     *    @param     string $fields
     *    @return    void
     */
	function drop($conditions,$fields = '')
	{
		$droped_rows = parent::drop($conditions, $fields);

		return $droped_rows;
	}
	/*
	* 判断名称是否唯一
	*/
	function unique($spec_name, $cate_id,$spec_id = 0)
	{
		//echo "aa";die();
		
		$conditions = "spec_name = '" . $spec_name . "' AND spec_id = ".$cate_id." AND spec_id != ".$spec_id."";
		//dump($conditions);
		return count($this->find(array('conditions' => $conditions))) == 0;
	}
}
?>